package knowse.app.daos;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class LogDataObject{
		private final String TAG = "LogDataObject";
		private String jsonClass;
		private String gitRepoPath;
		private Date timeStamp;
		ArrayList<CommitDataObject> commits;
		
		static SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SSS");
		
		public LogDataObject(JSONObject gitLog) throws Exception{
			this.jsonClass=gitLog.optString("json_class","null");
			this.gitRepoPath=gitLog.optString("GitRepoPath","null");
			String timeStampString = gitLog.optString("TimeStamp","null");
			this.timeStamp=df.parse(timeStampString);
			JSONArray jsonCommits=gitLog.getJSONArray("Commits");
			this.commits = new ArrayList<CommitDataObject>();
			for(int i=0;i<jsonCommits.length();i++)
			{
				JSONObject jobj= jsonCommits.getJSONObject(i);
				CommitDataObject cdo= new CommitDataObject(jobj);
				this.commits.add(i, cdo);
			}
		}
		
		public LogDataObject(){
			
		};
		
		
		public LogDataObject(String jsonClass, String gitRepoPath,
				Date timeStamp, ArrayList<CommitDataObject> commits) {
			super();
			this.jsonClass = jsonClass;
			this.gitRepoPath = gitRepoPath;
			this.timeStamp = timeStamp;
			this.commits = commits;
		}
		
		

		@Override
		public String toString() {
			return "jsonClass: " + jsonClass
					+ ", gitRepoPath: " + gitRepoPath + ", timeStamp: "
					+ df.format(timeStamp);
		}

		public String getJsonClass() {
			return jsonClass;
		}

		public void setJsonClass(String jsonClass) {
			this.jsonClass = jsonClass;
		}

		public String getGitRepoPath() {
			return gitRepoPath;
		}

		public void setGitRepoPath(String gitRepoPath) {
			this.gitRepoPath = gitRepoPath;
		}

		public Date getTimeStamp() {
			return timeStamp;
		}
		
		public String getTimeStamp2String(){
			df = new SimpleDateFormat("yyyy-MM-dd HH:mm.ss");
			return df.format(timeStamp);
		}

		public void setTimeStamp(Date timeStamp) {
			this.timeStamp = timeStamp;
		}
		
		public void setTimeStamp(String timeStampString) throws ParseException{
			df = new SimpleDateFormat("yyyy-MM-dd HH:mm.ss");
			this.timeStamp=df.parse(timeStampString);
		}

		public ArrayList<CommitDataObject> getCommits() {
			return commits;
		}

		public void setCommits(ArrayList<CommitDataObject> commits) {
			this.commits = commits;
		}


		
		
}
